package Thread.Test.Test3;

public class MyThread extends Thread{

    public static int num = 0;

    public static Object obj =new Object();
    @Override
    public void run() {
        while (true)
        {
            synchronized (obj) {
                if (num >= 100) {
                    break;
                } else {
                    num++;
                    if (num % 2 == 1) {
                        System.out.println(getName() + "输出" + num);
                    }
                    try {
                        sleep(100);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
}
